package com.hbnu.controller;

import com.hbnu.common.lang.Result;
import com.hbnu.pojo.Door;
import com.hbnu.service.DoorsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("/api")
public class DoorsController {
    @Autowired
    private DoorsService doorsService;

    @GetMapping("/doorList")
    @ResponseBody
    public Object getAllDoors() {
        List<Door> doorList = doorsService.getDoors();

        return Result.succ(200,"查询成功",doorList);
    }

    @GetMapping("/doorInfo")
    public Object getDoorById(Integer id){
        Door door = doorsService.getDoorById(id);
        return Result.succ(200,"查询成功",door);
    }
    @GetMapping("/deleteDoor")
    public Object deleteDoorById(int id){
        int flag = doorsService.deleteDoorById(id);
        return Result.succ(200,"删除成功",flag);
    }
    @GetMapping("/addDoor")
    public Object addDoor(Door door){
        int flag = doorsService.addDoor(door);
        return Result.succ(200,"添加成功",door);
    }
    @GetMapping("/updateDoor")
    public Object updateDoor(Door door,Model model){
        int flag = doorsService.updateDoor(door);
        return Result.succ(200,"更新成功",flag);
    }
}
